// NewsCover.vue
<template>
  <div class="news-cover">
    <img :src="coverUrl" class="news-cover__image" />
    <div class="news-cover__content">
      <h2 class="news-cover__title" @click="handleclick(id)">{{ title }}</h2>
      <p class="news-cover__summary">{{ summary }}</p>
      <div class="container">
        <p class="news-cover__info">
          <span class="news-cover__author">作者：{{ author }}</span>
          <span class="news-cover__views">浏览次数：{{ views }}</span>
          <span class="news-cover__created-at">创建时间：{{ createdAt }}</span>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'NewsCover',
  props: {
    coverUrl: {
      type: String,
      required: true
    },
    title: {
      type: String,
      required: true
    },
    summary: {
      type: String,
      required: true
    },
    author: {
      type: String,
      required: true
    },
    views: {
      type: Number,
      required: true
    },
    createdAt: {
      type: String,
      required: true
    },
    id:{
      type: Number,
      required: true
    }
  },
  methods:{
    handleclick(id){
      this.$router.push({ name: 'viewblog', params: { id: id } })
    }
  }
}
</script>

<style scoped>
.news-cover {
  display: flex;
  align-items: center;
  padding: 16px;
  box-sizing: border-box;
  background-color: #fff;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid #ccc;
}
.news-cover:hover{
  background-color: #f8f8f8;
}
.news-cover__image {
  flex: 0 0 128px;
  width: 128px;
  height: 128px;
  margin-right: 16px;
  margin-bottom: 8px;
}

.news-cover__content {
  flex: 1;
  padding: 16px 0;
}
.news-cover__title:hover {
  text-decoration: underline;
  color: #00a;
  cursor: pointer;
}
.container {
  position: relative;
  top: 50px;
}
.news-cover__title {
  margin: -40px 0 0 0;
  font-size: 18px;
  font-weight: bold;
  color: #333;
  line-height: 1.5;
}

.news-cover__summary {
  width: 80%;
  height: 100%;
  margin: 8px 0;
  font-size: 14px;
  color: #666;
  line-height: 1.5;
  text-indent: 1em;
}

.news-cover__info {
  position: relative;
  top: -19px;
  font-size: 12px;
  color: #999;
  display: flex;
  align-items: center;
  margin: 8px 0 0 0;
}

.news-cover__author,
.news-cover__views,
.news-cover__created-at {
  margin: 0 8px 0 0;
  font-size: 14px;
  color: #666;
}
</style>
